package com.ruoyi.farm.biz.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.farm.api.domain.ScoringDimension;
import com.ruoyi.farm.biz.service.IScoringDimensionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 评分维度Controller
 * 
 * @author Andy
 * @date 2022-07-24
 */
@RestController
@RequestMapping("/dimension")
public class ScoringDimensionController extends BaseController
{
    @Autowired
    private IScoringDimensionService scoringDimensionService;

    /**
     * 查询评分维度列表
     */
    @RequiresPermissions("farm:dimension:list")
    @GetMapping("/list")
    public TableDataInfo list(ScoringDimension scoringDimension)
    {
        startPage();
        List<ScoringDimension> list = scoringDimensionService.selectScoringDimensionList(scoringDimension);
        return getDataTable(list);
    }

    /**
     * 导出评分维度列表
     */
    @RequiresPermissions("farm:dimension:export")
    @Log(title = "评分维度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScoringDimension scoringDimension)
    {
        List<ScoringDimension> list = scoringDimensionService.selectScoringDimensionList(scoringDimension);
        ExcelUtil<ScoringDimension> util = new ExcelUtil<ScoringDimension>(ScoringDimension.class);
        util.exportExcel(response, list, "评分维度数据");
    }

    /**
     * 获取评分维度详细信息
     */
    @RequiresPermissions("farm:dimension:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(scoringDimensionService.selectScoringDimensionById(id));
    }

    /**
     * 新增评分维度
     */
    @RequiresPermissions("farm:dimension:add")
    @Log(title = "评分维度", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScoringDimension scoringDimension)
    {
        scoringDimension.setCreateBy(SecurityUtils.getUsername());
        return toAjax(scoringDimensionService.insertScoringDimension(scoringDimension));
    }

    /**
     * 修改评分维度
     */
    @RequiresPermissions("farm:dimension:edit")
    @Log(title = "评分维度", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScoringDimension scoringDimension)
    {
        return toAjax(scoringDimensionService.updateScoringDimension(scoringDimension));
    }

    /**
     * 删除评分维度
     */
    @RequiresPermissions("farm:dimension:remove")
    @Log(title = "评分维度", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scoringDimensionService.deleteScoringDimensionByIds(ids));
    }
}
